<!DOCTYPE html>
<style>
  #content {
    width: 1000px;
    height: 1000px;
  }
</style>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/gesture-util.js"></script>

<div id="content">
  <span id="select">This text is selected.</span>
</div>

<script type="text/javascript">
  var scrollTopBefore;
  var element = document.getElementById('select');

  function MouseWheelHandler(e) {
    return false;
  }
  // The autoscroll bug happens when there is a mousewheel event listener on
  // the page.
  element.addEventListener("mousewheel", MouseWheelHandler, false);

  promise_test (async () => {
    if (window.internals && internals.setPageScaleFactor(2.5) &&
          internals.setVisualViewportOffset(0, 30.2)) {
      element.scrollIntoView();
      scrollTopBefore = document.scrollingElement.scrollTop;
      var y = element.offsetHeight / 2;
      var endX = element.offsetWidth + 100;
      await mouseMoveTo(element.offsetLeft, y);
      await mouseDownAt(element.offsetLeft, y);
      await mouseMoveTo(endX - 30, y);
      await mouseMoveTo(endX, y);
      // Wait for the autoscroll timer to fire.
      await waitForCompositorCommit();
      assert_equals(document.scrollingElement.scrollTop, scrollTopBefore);
      document.getElementById('content').style.display = 'none';
    }
  }, "This is a test for http://crbug.com/516245. It ensures that pinch-zooming" +
     " and selecting doesn't autoscroll the page. To manually test, on Mac" +
     " pinch-zoom in and select text below. The page should not autoscroll.");
</script>
